{% extends "auth/base.html" %}

{% block title %}管理员控制台 - FlaskWeb{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">管理员控制台</h1>
</div>

<!-- 统计卡片 -->
<div class="row mb-4">
    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-primary shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">用户总数</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ stats.total_users }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-users fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-success shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-success text-uppercase mb-1">活跃用户</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ stats.active_users }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-user-check fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-info shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-info text-uppercase mb-1">角色总数</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ stats.total_roles }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-user-tag fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-warning shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">权限总数</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ stats.total_permissions }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-key fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 快速操作 -->
<div class="row">
    <div class="col-lg-6 mb-4">
        <div class="card shadow">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">快速操作</h6>
            </div>
            <div class="card-body">
                <div class="list-group list-group-flush">
                    <a href="{{ url_for('admin.users') }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">用户管理</h6>
                            <small>管理所有用户账户</small>
                        </div>
                        <p class="mb-1">添加、编辑、删除用户，管理用户角色和权限</p>
                    </a>
                    <a href="{{ url_for('admin.roles') }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">角色管理</h6>
                            <small>管理用户角色</small>
                        </div>
                        <p class="mb-1">创建、编辑角色，分配权限</p>
                    </a>
                    <a href="{{ url_for('admin.permissions') }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">权限管理</h6>
                            <small>管理系统权限</small>
                        </div>
                        <p class="mb-1">创建、编辑权限，查看权限使用情况</p>
                    </a>
                    <a href="{{ url_for('admin.system_logs') }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">系统日志</h6>
                            <small>查看系统活动</small>
                        </div>
                        <p class="mb-1">查看用户登录日志、操作日志等</p>
                    </a>
                </div>
            </div>
        </div>
    </div>

    <div class="col-lg-6 mb-4">
        <div class="card shadow">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">最近活动</h6>
            </div>
            <div class="card-body">
                {% if recent_activities %}
                <div class="list-group list-group-flush">
                    {% for activity in recent_activities %}
                    <div class="list-group-item">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">{{ activity.title }}</h6>
                            <small>{{ activity.created_at.strftime('%Y-%m-%d %H:%M') }}</small>
                        </div>
                        <p class="mb-1">{{ activity.description }}</p>
                        <small>用户: {{ activity.user.username }}</small>
                    </div>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted">暂无最近活动</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 系统信息 -->
<div class="row">
    <div class="col-lg-12 mb-4">
        <div class="card shadow">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">系统信息</h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <table class="table table-borderless">
                            <tr>
                                <td><strong>Flask版本:</strong></td>
                                <td>{{ system_info.flask_version }}</td>
                            </tr>
                            <tr>
                                <td><strong>Python版本:</strong></td>
                                <td>{{ system_info.python_version }}</td>
                            </tr>
                            <tr>
                                <td><strong>数据库:</strong></td>
                                <td>{{ system_info.database }}</td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table class="table table-borderless">
                            <tr>
                                <td><strong>环境:</strong></td>
                                <td>{{ system_info.environment }}</td>
                            </tr>
                            <tr>
                                <td><strong>启动时间:</strong></td>
                                <td>{{ system_info.start_time }}</td>
                            </tr>
                            <tr>
                                <td><strong>当前时间:</strong></td>
                                <td>{{ system_info.current_time }}</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}